#include <iostream>

#include <gtest/gtest.h>
#include "Counter.h"

using namespace std;

static Counter *c;

class FooEnvironment : public testing::Environment {
	public:
		virtual void SetUp(){
		    std::cout << "全局事件: FooEnvironment SetUP" << std::endl;
		}

		virtual void TearDown() {
		    std::cout << "全局事件: FooEnvironment TearDown" << std::endl;
		}
};

class TestSuite0:public testing::Test {
public:
    static void SetUpTestCase() {		//在第一个TestCase之前执行
        cout<<"TestSuite0事件: SetUpTestCase()"<<endl;
    	c = new Counter(0);
    }
 
    static void TearDownTestCase() {		//在最后一个TestCase之后执行
    	delete c;
        cout<<"TestSuite0事件: TearDownTestCase()"<<endl;
    }
    
	void SetUp() {						//在每个TestCase之前执行
        cout<<"TestCase事件: SetUp() is running"<<endl;
    }

    void TearDown() {					//在每个TestCase之后执行
        cout<<"TestCase事件: TearDown() is running"<<endl;
    } 
};

class TestSuite1:public testing::Test {
public:
    static void SetUpTestCase() {		//在第一个TestCase之前执行
        cout<<"TestSuite1事件: SetUpTestCase()"<<endl;
    	c = new Counter(2);
    }
 
    static void TearDownTestCase() {		//在最后一个TestCase之后执行
    	delete c;
        cout<<"TestSuite1事件: TearDownTestCase()"<<endl;
    }
    
	void SetUp() {						//在每个TestCase之前执行
        cout<<"TestCase事件: SetUp() is running"<<endl;
    }

    void TearDown() {					//在每个TestCase之后执行
        cout<<"TestCase事件: TearDown() is running"<<endl;
    } 
};



TEST_F(TestSuite0, Increment0)
{    
  // Test that counter 0 returns 0
  EXPECT_EQ(0, c->Decrement());

 
}
TEST_F(TestSuite0, Increment1)
{   
  // EXPECT_EQ() evaluates its arguments exactly once, so they
  // can have side effects.
  EXPECT_EQ(0, c->Increment());
  EXPECT_EQ(1, c->Increment());
  EXPECT_EQ(2, c->Increment());
  ASSERT_EQ(3, c->Decrement());
}
TEST_F(TestSuite1, Decrement)
{

    EXPECT_EQ(2, c->Decrement());   
    EXPECT_EQ(1, c->Decrement());
    EXPECT_EQ(0, c->Decrement());
    c->Print();
    EXPECT_EQ(0, c->Decrement());
    c->Print();
}

TEST_F(TestSuite1, Print)
{
    ASSERT_EQ(0, c->Decrement());
    c->Print();
    ASSERT_EQ(0, c->Increment());
    c->Print();
    EXPECT_EQ(1, c->Increment());
    c->Print();
    EXPECT_EQ(2, c->Decrement());
    c->Print();
}


int main(int argc, char** argv) {
    testing::AddGlobalTestEnvironment(new FooEnvironment);
    testing::InitGoogleTest(&argc, argv);
    return RUN_ALL_TESTS();
}
